﻿using System;
using System.Globalization;
using System.Windows.Data;
namespace CoreModule.Converters
{
    /// <summary>
    /// DbpPressure 转换为百分比。
    /// </summary>
    public class DbpPressureToProgressConverter : IValueConverter
    {
        /// <summary>
        /// 
        /// </summary>
        public double SourceBegin { get; set; } = 40;
        /// <summary>
        /// 
        /// </summary>
        public double SourceEnd { get; set; } = 180;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (int)Math.Min(100, Math.Abs(((int)value) - SourceBegin) * 100 / (SourceEnd - SourceBegin));
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
